package stephen.competition14;

import java.io.IOException;
import java.util.Hashtable;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



/**
 * Servlet implementation class Comment
 */
public class Comment extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Comment() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if (UserService.session.getAttribute("userInfo")==null ) {
			response.sendRedirect("stephenLogin.competition14.html");
		} else {   
			
			Hashtable h=(Hashtable)UserService.session.getAttribute("userInfo");
		String username=(String)h.get("username");
		String comment=request.getParameter("comment");
		System.out.println("name="+username+"   commment="+comment);
		UserService us=new UserService();
		boolean result=false;        
			result=us.comment(username, comment);
		
		if(result){
			
			
			response.sendRedirect("stephenloginSucess.html");
		}
		else{
			response.sendRedirect("stephenlogFail.html");
		}
		}
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
